package ModelLayer;
import java.util.*;

/**
 * Write a description of class ItemContainer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class ItemContainer
{
    private ArrayList<Item> items;
    private static ItemContainer instance;

    /**
     * Constructor for object of class ItemContainer.
     */
    public ItemContainer()
    {
        items = new ArrayList<Item>();
    }

    /**
     * Singleton, so only one instance of ItemContainer can be made.
     */
    public static ItemContainer getInstance()
    {
        if(instance==null)
        {
            instance = new ItemContainer();
        }
        return instance;
    }

    /**
     * Returns an item.
     * @param barCode, the barCode belonging to the item to be found
     * @return, the item found.
     */
    public Item findItem(String barCode)
    {
        int index = 0;
        boolean found = false;

        while(!found && index < items.size())
        {
            if(items.get(index).getBarCode().equals(barCode))
            {
                found = true;
            }
            else
            {
                index++;
            }
        }
        return items.get(index);
    }

    /**
     * Adds an item to the arraylist on itemcontainer.
     * @param item, the item to be added. 
     */
    public void addItem(Item item)
    {
        items.add(item);
    }
}
